﻿using System.Text.RegularExpressions;

namespace Tab2Sql
{
    internal partial class TSV2DataTable
    {
        /// <summary>
        /// Get's an array of columns as split by the global separator.
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        private string[] getFields(string line)
        {
            string[] tmpArray = Regex.Split(line, GlobalSeparator);
            int items = tmpArray.Length;
            if (tmpArray[items - 1].Length < 1)
            {
                items--;
            }
            line = null;
            return (string[]) DGen.DGen.ResizeArray(tmpArray, items);
        }


        // PRIVATE METHODS (MINOR)
        // ----------------------------------------------------------------------------------------------------
        //  columnNameAdjustment
        //          (straight forward, makes column names suitable for SQL use - exact handling depends on tab2sql.Options.ColumnNameHandling)

        private void addColumn(string colHeader, int q)
        {
            
            if (Dt.Columns.Contains(colHeader) == false)
            {
                Dt.Columns.Add(colHeader);
            }
            else
            {
                do
                {
                    colHeader = "[CX" + q.ToString() + "]";
                    q++;
                } while (Dt.Columns.Contains(colHeader));
                Dt.Columns.Add(colHeader);
            }
        }

        /// <summary>
        /// Possibly redundant (27th October 2009)
        /// </summary>
        /// <param name="column"></param>
        /// <returns></returns>
        private string columnNameAdjustment(string column)
        {
            var columnNameSettings = new HandlingOfColumnNames();
            columnNameSettings = MyOptions.columnNameModel;
            switch (columnNameSettings)
            {
                case HandlingOfColumnNames.NoChanges:
                    // foo.
                    break;
                case HandlingOfColumnNames.JustAddQuotes:
                    column = "[" + column + "]";
                    break;
                case HandlingOfColumnNames.Standard:
                    column = DGen.DText.FixColumnHeader(column);

                    break;
                default:

                    break;
            }
            return column;
        }
       
    }
}